package com.zhl.media.commonres.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.zhl.media.commonres.R;

public class EmptyLayout extends FrameLayout {

    private Context mContext;
    private View mEmptyView;
    private View mBindView;
    private TextView mEmptyText;

    public EmptyLayout(Context context) {
        this(context, null);
    }

    public EmptyLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public EmptyLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext=context;
        LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        //居中
        params.gravity = Gravity.CENTER;
        //数据为空时的布局
        mEmptyView = View.inflate(context, R.layout.public_layout_empty, null);
        mEmptyText =(TextView)mEmptyView.findViewById(R.id.tvEmptyText);
        addView(mEmptyView,params);

//        //加载中的布局
//        int loadingLayout = ta.getResourceId(R.styleable.EmptyLayout_elLoadingLayout, R.layout.layout_loading);
//        mLoadingView = View.inflate(context, loadingLayout, null);
//        tvLoadingText =(TextView)mLoadingView.findViewById(R.id.tvLoadingText);
//        addView(mLoadingView,params);
//
//        //错误时的布局
//        int errorLayout = ta.getResourceId(R.styleable.EmptyLayout_elErrorLayout, R.layout.layout_error);
//        mErrorView = View.inflate(context, errorLayout, null);
//        mBtnReset =(Button)mErrorView.findViewById(R.id.btnReset);
//        addView(mErrorView, params);
        mEmptyView.setVisibility(View.GONE);
    }


    public void showEmpty(String text) {
        if (mBindView != null) mBindView.setVisibility(View.GONE);
        if (!TextUtils.isEmpty(text)) mEmptyText.setText(text);
        mEmptyView.setVisibility(View.VISIBLE);
    }

    public void hideEmpty() {
        if (mBindView != null) mBindView.setVisibility(View.VISIBLE);
        mEmptyView.setVisibility(View.GONE);
    }

    public void bindView(View view) {
        mBindView = view;
    }
}